<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据模版定义规范</title>
</head>

<body>
    <script src="https://cdn.bootcdn.net/ajax/libs/Mock.js/1.0.1-beta3/mock-min.js"></script>
    <h2>数据模版定义规范-根据数据模板生成模拟数据：Mock.mock( template )</h2>
    F12打开控制台查看更方便
    <div class="box">
        展示内容:<div id="content"></div>
    </div>
    <script>

        //生成数据
        list = Mock.mock({
            "将一个字符串随机重复1到10遍|1-10": "★",
            "将一个字符串随机重复5遍|5": "★",
            "随机生成一个布尔值，概率都是0.5|1": true,
            "从属性值 {} 中随机选取 2 个属性|2": {
                "310000": "上海市",
                "320000": "江苏省",
                "330000": "浙江省",
                "340000": "安徽省"
            },
            "从属性值 {} 中随机选取 2到4个 个属性|2-4": {
                "310000": "上海市",
                "320000": "江苏省",
                "330000": "浙江省",
                "340000": "安徽省"
            },
            "从属性值 [{}, {} ...] 中随机选取 1 个元素，作为最终值|1": [
                { title: "AMD" },
                { title: "CMD" },
                { title: "UMD" },
            ],
            "通过重复属性值 [{}, {} ...] 生成一个新数组，重复次数大于等于 2，小于等于 3|2-3": [
                { title: "AMD" },
                { title: "CMD" },
                { title: "UMD" },
            ],
            '传入一个正则，返回符合正则的字符串': /[a-z][A-Z][0-9]/
        })

        // {
        //   "string": "★★★"
        // }

        //展示数据
        console.table(list)
        x = document.getElementById("content");
        //将对象转为JSON
        x.innerHTML = JSON.stringify(list, null, '<br />');
    </script>

</body>

</html>